package Command;

import java.util.ArrayList;

/**
 * CommandStack
 * Simple stack for commands.
 * Threadsafe!
 * Stack for commands
 * @author Danny
 *
 */

public class CommandStack {
	// Arraylist containing commandos
	private ArrayList<Command> arrCommandos = new ArrayList<Command>();
	/**
	 * isEmpty
	 * @return True if list is empty, false otherwise
	 */
	public boolean isEmpty()
	{
		synchronized (arrCommandos) {
			return arrCommandos.isEmpty();
		}
	}
	/**
	 * push
	 * Put the command on the stack
	 * @param p_cmdCommand
	 */
	public void push(Command p_cmdCommand)
	{
		synchronized (arrCommandos) {
			arrCommandos.add(p_cmdCommand);
		}
	}
	/**
	 * pop
	 * Pop a command from the stack, if not empty.
	 * Removes the command from the stack.
	 * @return
	 */
	public Command pop()
	{
		Command tmp = new NoCommand();
		synchronized (arrCommandos) {
			if(arrCommandos.isEmpty())
			{
				return tmp;
			}
			tmp = arrCommandos.get(0);
			arrCommandos.remove(0);
			return tmp;
		}
	}
}
